#!/usr/bin/env python
# -*- coding: utf-8 -*-
from re import match, sub


def discard(app, prefix, replacement='', key='SCRIPT_NAME'):
    """ remove matching prefix from WSGI environment key

    """
    def discard_app(environ, start_response):
        value = environ.get(key, '')
        if match(prefix, value):
            environ[key] = sub(prefix, replacement, value)
        return app(environ, start_response)
    return discard_app


def shift_path(app, prefix):
    """ move matching prefix from SCRIPT_NAME to PATH_INFO

    """
    def shift_path_app(environ, start_response):
        pass
    return shift_path_app



def shift_script(app, prefix):
    """ move matching prefix from PATH_INFO to SCRIPT_NAME

    """
    def shift_script_app(environ, start_response):
        pass
    return shift_script_app
